﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
namespace OnlineBookStore
{
    public partial class LoginWebForm : MyPageBase
    {

        protected override void OnPreInit(EventArgs e)
        {
            string relogin = Request.QueryString["reLogin"];
            if (relogin!=null&&relogin.Equals("true"))
                FormsAuthentication.SignOut();
            base.OnPreInit(e);
        }


        protected void Login1_LoggedIn(object sender, EventArgs e)
        {
            string preUrl = Request.QueryString["cururl"];
            if (preUrl != null)
               Response.Redirect(preUrl);
            else
                Response.Redirect("~/Default.aspx");
        }
        /// <summary>
        /// 显示具体的登陆错误信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Login1_LoginError(object sender, EventArgs e)
        {
            MembershipUser userInfo = Membership.GetUser(Login1.UserName);
            if (userInfo == null)
                Login1.FailureText = "不存在用户 " + Login1.UserName;
            else if (!userInfo.IsLockedOut)
                Login1.FailureText = "用户 " + Login1.UserName + " 由于密码连续错误" + Membership.MaxInvalidPasswordAttempts + "次被锁定";
            else if (Login1.Password.Length < Membership.MinRequiredPasswordLength)
                Login1.FailureText = "请输入" + Membership.MinRequiredPasswordLength + "位以上的密码";
        }
    }
}
